package com.ehl.capture.db;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Properties;
import org.apache.log4j.Logger;

public class DBLoader
{
    public static Logger log = Logger.getLogger(DBLoader.class);
    private static String confPath = System.getProperty("user.dir") + "/conf/db.properties";
    public static String jdbcurl;
    public static String user;
    public static String password;
    public static String minpoolsize;
    public static String maxpoolsize;
    public static String initialpoolsize;
    public static String acquireincrement;
    public static String maxidletime;
    public static String acquireretryattempts;
    public static String acquireretrydelay;
    public static String checkouttimeout;
    public static String debugunreturnedconnectionstacktraces;
    public static String unreturnedconnectiontimeout;

    static
    {
        init();
    }

    public static void init() {
        log.info("配置文件加载开始");
        getStaticConf();
        log.info("配置文件加载完毕");
    }

    private static boolean getStaticConf()
    {
        File f = new File(confPath);
        if (!f.exists()) {
            System.out.println("配置文件不存在,程序退出!");
            log.error("配置文件不存在,程序退出!");
            System.exit(-1);
            return false;
        }

        Properties p = new Properties();
        FileReader fr = null;
        try {
            fr = new FileReader(f);
            p.load(fr);

            jdbcurl = p.getProperty("jdbcurl");
            user = p.getProperty("user");
            password = p.getProperty("password");
            minpoolsize = p.getProperty("minpoolsize");
            maxpoolsize = p.getProperty("maxpoolsize");
            initialpoolsize = p.getProperty("initialpoolsize");
            acquireincrement = p.getProperty("acquireincrement");
            maxidletime = p.getProperty("maxidletime");
            acquireretryattempts = p.getProperty("acquireretryattempts");
            acquireretrydelay = p.getProperty("acquireretrydelay");
            checkouttimeout = p.getProperty("checkouttimeout");
            debugunreturnedconnectionstacktraces = p.getProperty("debugunreturnedconnectionstacktraces");
            unreturnedconnectiontimeout = p.getProperty("unreturnedconnectiontimeout");
        } catch (IOException e) {
            log.error("静态配置文件加载错误", e);
            System.exit(-1);
            return false;
        } finally {
            if (fr != null)
                try {
                    fr.close();
                } catch (IOException localIOException2) {
                }
        }
        return true;
    }
}